﻿@{
    ViewBag.Title = "Index";
}

<h2>Music Index</h2>
<div>    
</div>
<p>
    @ViewBag.strHtml
</p>
@section Scripts{
    <script>
        $(function () {
            //$.ajax({
            //    type: "POST",
            //    url: 'http://localhost:3125/BookApi/BooksByCategory',
            //    headers: {
            //        'token': 'isc',
            //        'username': 'zyp',
            //        pwd: '2017'
            //    },
            //    data:{
            //        typeid: 1
            //    },
            //    dataType: "json",
            //    success: function (data) {
            //        console.log(data);
            //    },
            //    beforeSend: function () {
            //        $("#loading").show();
            //    },
            //    complete: function () {
            //        $("#loading").hide();
            //    }
            //});

            $.ajax({
                type: "GET",
                url: 'http://localhost:3125/api/music',
                headers: {
                    'token': 'isc',
                    'username': 'zyp',
                    pwd: '2017'
                },
                data: {
                    typeid: 1
                },
                dataType: "json",
                success: function (data) {
                    console.log(data);

                },
                beforeSend: function () {
                    $("#loading").show();
                },
                complete: function () {
                    $("#loading").hide();
                }
            });
        })

        function loadMusic() {
            $.ajax({
                type: "POST",
                url: 'http://route.showapi.com/213-4?showapi_sign=3f0c698c4357477ba780198b22f4eeaf&showapi_appid=35037&topid=26',
                dataType: "json",
                success: function (data) {


                    //保存歌曲
                    if (data.showapi_res_body && data.showapi_res_body.pagebean && data.showapi_res_body.pagebean.songlist) {
                        var songlist = data.showapi_res_body.pagebean.songlist.splice(0, 2);
                        console.log(songlist);
                        console.log(JSON.stringify(songlist));
                        writeLog(songlist);
                        //writeLogSong(songlist[0]);
                    }

                },
                beforeSend: function () {
                    $("#loading").show();
                },
                complete: function () {
                    $("#loading").hide();
                }
            });
        }

        function writeLog(songlist) {
            $.ajax({
                type: "POST",
                url: '@Url.Action("WriteLog", "Music")',
                dataType: "json",
                data: {
                    songList: songlist,
                    msg: new Date()
                },
                success: function (data) {
                    console.log('writeLog', data);
                }
            });
        }

        function writeLogSong(song) {
            $.ajax({
                type: "POST",
                url: '@Url.Action("WriteLogSong", "Music")',
                dataType: "json",
                data: {
                    song: song,
                    msg: new Date()
                },
                success: function (data) {
                    console.log('writeLog', data);
                }
            });
        }
    </script>
}
